//
//  TimeStamp.m
//  Air
//
//  Created by 沃特奇 on 16/10/9.
//  Copyright © 2016年 董国政. All rights reserved.
//

#import "TimeStamp.h"

@implementation TimeStamp
+(NSString *)getTimeStamp
{
    NSString *ts=[NSString stringWithFormat:@"%ld",time(NULL)];
    return ts;
}
+(NSString *)getBase64codewithStr:(NSString *)str
{
    NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
    NSString *base64=[data base64EncodedStringWithOptions:0];
    return base64;
}
+ (NSString *)dateStrFromCstampTime:(NSInteger)timeStamp
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}
+(NSString *)timeStrFromDate:(NSString *)data1 WithToDate:(NSString *)data2
{
    NSDateFormatter *date=[[NSDateFormatter alloc] init];
    [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSCalendar *cal=[NSCalendar currentCalendar];
    unsigned int unitFlags=NSCalendarUnitYear| NSCalendarUnitMonth| NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
    NSDateComponents *d = [cal components:unitFlags fromDate:[date dateFromString:data1] toDate:[date dateFromString:data2] options:0];
  
    NSString *str=[NSString stringWithFormat:@"%ld",[d day]*24*60*60+[d hour]*60*60+[d minute]*60+[d second]];
    return str;
}
@end
